package com.example.librarymanagementproject2.converter;

import com.example.librarymanagementproject2.model.document.UserDocument;
import com.example.librarymanagementproject2.model.entity.User;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

/**
 * @ClassName UserConverter
 * @Description 用户转换器
 * @Author Kx
 * @Date 2025/10/23 15:16
 * @Version 1.0
 */
@Mapper(componentModel = "spring")
public interface UserConverter {

    /**
     * @author: kx
     * @date: 2025/10/23 15:19
     * @param user : 用户对象信息
     * @description: 用户对象信息转换成用户文档信息
    */
    @Mappings({
            @Mapping(source = "id", target = "id"),
            @Mapping(source = "username", target = "username"),
            @Mapping(source = "realName", target = "realName"),
            @Mapping(source = "role", target = "role"),
            @Mapping(source = "status", target = "status"),
            @Mapping(source = "email", target = "email"),
            @Mapping(source = "maxBorrowNum", target = "maxBorrowNum"),
            @Mapping(source = "createTime", target = "createTime"),
            @Mapping(source = "updateTime", target = "updateTime"),
            @Mapping(source = "cancelTime", target = "cancelTime")
    })
    UserDocument toUserDocument(User user);

    /**
     * @author: kx
     * @date: 2025/10/27 11:55
     * @param userDocument : 用户文档信息
     * @return com.example.librarymanagementproject2.model.entity.User
     * @description: 用户文档信息转换成用户对象信息
    */
    User toUser(UserDocument userDocument);
}
